local xionghuo = fk.CreateSkill {

  name = "joy__xionghuo",

  tags = {  },

}



xionghuo:addEffect("active", {
  name = "joy__xionghuo",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:getMark("@joy__baoli") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id and Fk:currentRoom():getPlayerById(to_select):getMark("@joy__baoli") == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:removePlayerMark(player, "@joy__baoli", 1)
    room:addPlayerMark(target, "@joy__baoli", 1)
  end,
})

xionghuo:addEffect(fk.GameStart, {
  name = "#joy__xionghuo_record",
  --xionghuo,
  anim_type = "offensive",
  events = {fk.GameStart, fk.DamageCaused, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(xionghuo.name) then
      if event == fk.GameStart then
        return true
      elseif event == fk.DamageCaused then
        return target == player and data.to ~= player and data.to:getMark("@joy__baoli") > 0
      else
        return target ~= player and target:getMark("@joy__baoli") > 0 and target.phase == Player.Play
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("joy__xionghuo")
    if event == fk.GameStart then
      room:addPlayerMark(player, "@joy__baoli", 3)
    elseif event == fk.DamageCaused then
      room:doIndicate(player.id, {data.to.id})
      data.damage = data.damage + 1
    else
      room:doIndicate(player.id, {target.id})
      room:removePlayerMark(target, "@joy__baoli", 1)
      local n = 3
      if target:isNude() then
        n = 2
      end
      local rand = math.random(1, n)
      if rand == 1 then
        room:damage {
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = "joy__xionghuo",
        }
        local mark = target:getTableMark( "joy__xionghuo_prohibit-turn")
        table.insert(mark, player.id)
        room:setPlayerMark(target, "joy__xionghuo_prohibit-turn", mark)
      elseif rand == 2 then
        room:loseHp(target, 1, "joy__xionghuo")
        room:addPlayerMark(target, "MinusMaxCards-turn", 1)
      else
        local dummy = Fk:cloneCard("dilu")
        if not target:isKongcheng() then
          dummy:addSubcard(table.random(target.player_cards[Player.Hand]))
        end
        if #target.player_cards[Player.Equip] > 0 then
          dummy:addSubcard(table.random(target.player_cards[Player.Equip]))
        end
        room:obtainCard(player, dummy, false, fk.ReasonPrey)
      end
    end
  end,
})
xionghuo:addEffect(fk.DamageCaused, {
  name = "#joy__xionghuo_record",
  --xionghuo,
  anim_type = "offensive",
  events = {fk.GameStart, fk.DamageCaused, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(xionghuo.name) then
      if event == fk.GameStart then
        return true
      elseif event == fk.DamageCaused then
        return target == player and data.to ~= player and data.to:getMark("@joy__baoli") > 0
      else
        return target ~= player and target:getMark("@joy__baoli") > 0 and target.phase == Player.Play
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("joy__xionghuo")
    if event == fk.GameStart then
      room:addPlayerMark(player, "@joy__baoli", 3)
    elseif event == fk.DamageCaused then
      room:doIndicate(player.id, {data.to.id})
      data.damage = data.damage + 1
    else
      room:doIndicate(player.id, {target.id})
      room:removePlayerMark(target, "@joy__baoli", 1)
      local n = 3
      if target:isNude() then
        n = 2
      end
      local rand = math.random(1, n)
      if rand == 1 then
        room:damage {
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = "joy__xionghuo",
        }
        local mark = target:getTableMark( "joy__xionghuo_prohibit-turn")
        table.insert(mark, player.id)
        room:setPlayerMark(target, "joy__xionghuo_prohibit-turn", mark)
      elseif rand == 2 then
        room:loseHp(target, 1, "joy__xionghuo")
        room:addPlayerMark(target, "MinusMaxCards-turn", 1)
      else
        local dummy = Fk:cloneCard("dilu")
        if not target:isKongcheng() then
          dummy:addSubcard(table.random(target.player_cards[Player.Hand]))
        end
        if #target.player_cards[Player.Equip] > 0 then
          dummy:addSubcard(table.random(target.player_cards[Player.Equip]))
        end
        room:obtainCard(player, dummy, false, fk.ReasonPrey)
      end
    end
  end,
})
xionghuo:addEffect(fk.EventPhaseStart, {
  name = "#joy__xionghuo_record",
  --xionghuo,
  anim_type = "offensive",
  events = {fk.GameStart, fk.DamageCaused, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(xionghuo.name) then
      if event == fk.GameStart then
        return true
      elseif event == fk.DamageCaused then
        return target == player and data.to ~= player and data.to:getMark("@joy__baoli") > 0
      else
        return target ~= player and target:getMark("@joy__baoli") > 0 and target.phase == Player.Play
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("joy__xionghuo")
    if event == fk.GameStart then
      room:addPlayerMark(player, "@joy__baoli", 3)
    elseif event == fk.DamageCaused then
      room:doIndicate(player.id, {data.to.id})
      data.damage = data.damage + 1
    else
      room:doIndicate(player.id, {target.id})
      room:removePlayerMark(target, "@joy__baoli", 1)
      local n = 3
      if target:isNude() then
        n = 2
      end
      local rand = math.random(1, n)
      if rand == 1 then
        room:damage {
          from = player,
          to = target,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = "joy__xionghuo",
        }
        local mark = target:getTableMark( "joy__xionghuo_prohibit-turn")
        table.insert(mark, player.id)
        room:setPlayerMark(target, "joy__xionghuo_prohibit-turn", mark)
      elseif rand == 2 then
        room:loseHp(target, 1, "joy__xionghuo")
        room:addPlayerMark(target, "MinusMaxCards-turn", 1)
      else
        local dummy = Fk:cloneCard("dilu")
        if not target:isKongcheng() then
          dummy:addSubcard(table.random(target.player_cards[Player.Hand]))
        end
        if #target.player_cards[Player.Equip] > 0 then
          dummy:addSubcard(table.random(target.player_cards[Player.Equip]))
        end
        room:obtainCard(player, dummy, false, fk.ReasonPrey)
      end
    end
  end,
})

xionghuo:addEffect("prohibit", {
  name = "#joy__xionghuo_prohibit",
  is_prohibited = function(self, from, to, card)
    return card.trueName == "slash" and table.contains(from:getTableMark( "joy__xionghuo_prohibit-turn") ,to.id)
  end,
})

return xionghuo